package com.itstherules.jmsunit.mock.activemq;

import static com.itstherules.jmsunit.JmsUnit.sender;
import static com.itstherules.jmsunit.JmsUnit.mock;
import static com.itstherules.jmsunit.expectation.Expectations.headers;
import static com.itstherules.jmsunit.expectation.XmlBasedExpectations.xPathEq;
import static com.itstherules.jmsunit.expectation.XmlBasedExpectations.xmlEq;
import static com.itstherules.jmsunit.expectation.XmlLoaders.xml;

import org.junit.Before;
import org.junit.Test;

import com.itstherules.jmsunit.JmsInlineMock;
import com.itstherules.jmsunit.JmsSender;
import com.itstherules.jmsunit.managers.QueueManagersFactory.QueueManagerType;


public class JmsFileLoadingTest {

	private JmsInlineMock stub;
	private JmsSender sender;
	
	@Before
	public void create() throws Exception {
		stub = mock("vm://localhost:61616", QueueManagerType.ActiveMQ);
		sender = sender("blue", "vm://localhost:61616", QueueManagerType.ActiveMQ);
	}
	
	@Test
	public void loadXmlAndXmlExpectation() throws Exception {
			stub.expects().through("blue").with(xmlEq(xml("simpletest/simpleTest")));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
	
	@Test
	public void loadXmlAndXPathExpectation() throws Exception {
			stub.expects().through("blue").with(xPathEq("amno1", "/abc/pq/ab[1]"));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
	
	@Test
	public void loadXmlAndXPathExpectation2nd() throws Exception {
			stub.expects().through("blue").with(xPathEq("amno2", "/abc/pq/ab[2]"));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
	
	
	@Test
	public void loadXmlAndXPathExpectationForValue() throws Exception {
			stub.expects().through("blue").with(xPathEq("amno3", "/abc/pq/ab1"));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
	
	
	@Test
	public void loadXmlAndXPathExpectationCountChildNodes() throws Exception {
			stub.expects().through("blue").with(xPathEq("2", "count(/abc/pq/ab)"));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
	
	@Test
	public void loadXmlAndXPathExpectationCountAllChildren() throws Exception {
			stub.expects().through("blue").with(xPathEq("3", "count(/abc/pq/*)"));
			sender.send(xml("simpletest/simpleTest"), headers("Blue2"));
			stub.verifyAndClose();
	}
}
